<template>
  <div class="AssetList">
    <el-main>
      <div>
        <el-form :model="form">
          <el-row>
            <el-col :span="12">
              <div class="grid-content bg-purple">
                <el-form-item label="任务单名称">
                  <el-input v-model="form.name" style="width:340px"></el-input>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="12">
              <div class="grid-content bg-purple-light">
                <el-form-item label="分配用户">
                  <el-select
                    v-model="form.userList1"
                    multiple
                    placeholder="管理员"
                    style="width:340px"
                  >
                    <!-- <el-option label="管理员" value="all"></el-option>
                    <el-option label="普通用户" value="completed "></el-option>
                    <el-option label="超级管理员" value="unfinished"></el-option>-->
                    <el-option
                      v-for="item in list"
                      :key="item.id"
                      :label="item.username"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
        </el-form>
        <hr>
        <!-- <br> -->
        <el-form ref="form" :model="form" label-width="80px">
          <el-row :gutter="20">
            <el-col :span="6">
              <div class="grid-content bg-purple">
                <!-- <el-form-item label="资产类别">
                  <el-select v-model="form.assetType" placeholder="请选择资产类别" style="width:180px">
                    <el-option label="土地、房屋及建筑物" value="Houses"></el-option>
                    <el-option label="通用设备" value="FlexibleUnit"></el-option>
                    <el-option label="专用设备" value="SpecialEquipment"></el-option>
                    <el-option label="交通运输设备" value="TransportEquipment"></el-option>
                    <el-option label="电气设备" value="ElectricalEquipment"></el-option>
                    <el-option label="电子产品及通讯设备" value="ElectronicProducts"></el-option>
                    <el-option label="仪器仪表设备" value="Instrument"></el-option>
                    <el-option label="文艺体育设备" value="SportsEquipment"></el-option>
                    <el-option label="图书文物及陈列品" value="Books"></el-option>
                    <el-option label="家具用具及其他类" value="Furniture"></el-option>
                  </el-select>
                </el-form-item>-->
                <el-form-item label="资产类别" prop="assetTypeId">
                  <el-select
                    v-model="form.assetTypeId"
                    @change="consolelog1"
                    placeholder="请选择资产类别"
                    style="width:180px"
                  >
                    <el-option
                      v-for="item in list1"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="grid-content bg-purple">
                <el-form-item label="资产名称">
                  <el-input v-model="form.assetName"></el-input>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="grid-content bg-purple-light">
                <el-form-item label="公司部门:">
                  <el-select v-model="form.department" placeholder="请选择公司部门">
                    <el-option label="* 市场部" value="marketingDepartment"></el-option>
                    <el-option label="* 销售部" value="salesDepartment"></el-option>
                    <el-option label="* 产品部" value="productDepartment"></el-option>
                    <el-option label="* 研发部" value="researchDepartment"></el-option>
                    <el-option label="* 生产部" value="productDepartment"></el-option>
                    <el-option label="* 人力资源部" value="resourcesDepartment"></el-option>
                  </el-select>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="grid-content bg-purple">
                <el-button type="primary" icon="el-icon-search" style="margin:0 5px 0 26px;">搜索</el-button>
                <el-button type="primary" style="margin:0 0 0 22px;">
                  <router-link to="/User">新增用户</router-link>
                </el-button>
              </div>
            </el-col>
          </el-row>
          <!-- <el-row :gutter="20">
            <el-col :span="12">
              <div class="grid-content bg-purple">
                <div class="block">
                  <span class="demonstration"> 购入日期:</span>
                  <el-date-picker
                    v-model="value6"
                    type="daterange"
                    range-separator="-"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                  ></el-date-picker>
                </div>
              </div>
            </el-col>
             <el-button type="primary" icon="el-icon-search">搜索</el-button>
            <el-button type="primary" @click="dialogFormVisible = true" icon="el-icon-menu">新建盘点任务单</el-button>
            <el-dialog title="新建盘点单" :visible.sync="dialogFormVisible">
              <el-form :model="form">
                <el-form-item label="任务单名称" :label-width="formLabelWidth">
                  <el-input v-model="form.PropertyName" auto-complete="off" style="width:300px"></el-input>
                </el-form-item>
                <el-form-item label="分类用户" :label-width="formLabelWidth">
                  <el-input v-model="form.PropertyType" auto-complete="off" style="width:300px"></el-input>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogFormVisible = false">
                  <router-link to="/CountingTask">创 建</router-link>
                </el-button>
              </div>
            </el-dialog> 
          </el-row>-->
        </el-form>
      </div>
      <el-table
        ref="multipleTable"
        :data="tableData3"
        border
        height="273"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="state" label="状态" width="150" :formatter="formatState"></el-table-column>
        <el-table-column prop="pictureUrl" label="照片" width="120"></el-table-column>
        <el-table-column prop="assetCode" label="资产编号" width="120"></el-table-column>
        <el-table-column prop="assetName" label="资产名称" width="120"></el-table-column>
        <el-table-column prop="standardType" label="规格" width="300"></el-table-column>
        <el-table-column prop="sn" label="SN号" width="120"></el-table-column>
        <el-table-column prop="unit" label="计量单位" width="120"></el-table-column>
        <el-table-column prop="amount" label="金额(单位:万元)" width="200"></el-table-column>
        <el-table-column prop="useCompany" label="使用公司" width="120"></el-table-column>
        <el-table-column prop="useDept" label="使用部门" width="120"></el-table-column>
        <el-table-column prop="buyDate" label="购入时间" width="120"></el-table-column>
        <el-table-column prop="useUser" label="使用人" width="120"></el-table-column>
        <el-table-column prop="ownCompany" label="所属公司" width="300"></el-table-column>
        <el-table-column prop="area" label="区域" width="120"></el-table-column>
        <el-table-column prop="storageLocation" label="存放地点" width="120"></el-table-column>
        <el-table-column prop="deadLine" label="使用期限(月)" width="120"></el-table-column>
        <el-table-column prop="assetAdmin" label="管理员" width="120"></el-table-column>
      </el-table>
      <br>
      <div class="block">
        <el-row :gutter="20">
          <el-col :span="20">
            <div class="grid-content bg-purple">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage4"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="10"
                layout="prev, pager, next, sizes, jumper"
                :total="400"
              ></el-pagination>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="grid-content bg-purple">
              <el-button type="primary">取消</el-button>
              <el-button type="primary" @click="saveData">保存</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-main>
  </div>
</template>
<script>
import { axiosPost, axiosGet } from "@/api/index.js";
export default {
  data() {
    return {
      form: {
        assetTypeId: "",
        userList: "",
        userList1: [],
        assetName: "",
        user: "",
        department: "",
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
        assetList:"",
      },
      tableData3: [
        /*  {
          state: "在用",
          pictureUrl: "",
          assetCode: "123456",
          assetName: "奔驰"
        }, 
        {
          state: "报废",
          pictureUrl: "",
          assetCode: "123456",
          assetName: "奔驰"
        },
        {
          state: "闲置",
          pictureUrl: "",
          assetCode: "123456",
          assetName: "奔驰"
        },
        {
          state: "在用",
          pictureUrl: "",
          assetCode: "123456",
          assetName: "奔驰"
        },
        {
          state: "在用",
          pictureUrl: "",
          assetCode: "123456",
          assetName: "奔驰"
        },
        {
          state: "在用",
          pictureUrl: "",
          assetCode: "123456",
          assetName: "奔驰"
        },
        {
          state: "在用",
          pictureUrl: "",
          assetCode: "123456",
          assetName: "奔驰"
        } */
      ],
      value6: "",
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
      multipleSelection: [],
      dialogTableVisible: false,
      dialogFormVisible: false,
      formLabelWidth: "120px",
      list: [],
      list1: []
    };
  },
  beforeMount() {
    //资产列表接口
    axiosGet("Asset/GetAssetTypeList", null).then(res => {
      if (res.status === 200 && res.data.success) {
        this.list1 = res.data.data;
      } else {
      }
    });
    //获取员工列表接口
    axiosGet("Account/GetStaffList", null).then(res => {
      if (res.status === 200 && res.data.success) {
        this.list = res.data.data;
      } else {
      }
    });
  },
  //获取资产列表接口数据
  created() {
    axiosGet(
      "/Asset/GetAssetList?userId=D52A08C4-3A0B-4A4A-B929-89E7E45481E2",
      null
    ).then(res => {
      if (res.status == 200 && res.data.success) {
        this.tableData3 = res.data.data;
      }
    });
  },
  methods: {
    toggleSelection(rows) {
      console.log(rows);
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      console.log(val);
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    //将数据库对应的数字转换成在用 闲置 报废
    formatState: function(row, column) {
      return row.state === 1 ? "闲置" : row.state === 2 ? "在用" : "报废";
    },
    consolelog1() {
      // console.log(this.ruleForm.moudle);
    },
    //创建盘点任务单接口
    saveData() {
      debugger;
      var arr = [];
      for (var i = 0; i < this.form.userList1.length; i++) {
        var bean = { userId: "" };
        var str = this.form.userList1[i];
        bean.userId = str;
        arr.push(bean);
      }
      this.form.userList = JSON.stringify(arr);
      // this.form.userList = JSON.stringify(this.form.userList1);
      console.log(JSON.stringify(arr));
      axiosPost("Task/CreateTask", this.form).then(res => {
        if (res.status === 200 && res.data.success) {
          // this.form = res.data.data;
          this.$message({
            showClose: true,
            message: "恭喜你，任务单创建成功",
            type: "success"
          });
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
</style>
